package com.gz.logistics.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gz.logistics.R;
import com.gz.logistics.library.pojo.CustomerSpinnerObject;
import com.gz.logistics.library.pojo.PartInfo;
import com.gz.logistics.library.util.CrashHandler;

import java.util.List;

/**
 * author wanner1991
 */
public  class SpinnerAdapter extends BaseAdapter{
    private String TAG = SpinnerAdapter.class.getSimpleName();
    private Context mContext;
    private List<CustomerSpinnerObject> mDataList;

    public SpinnerAdapter(Context mContext, List<CustomerSpinnerObject> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList.get(i).toString();
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(mContext).inflate(R.layout.spiner_item_layout,null);
            holder = new ViewHolder();
            holder.tv_part_name = (TextView) view.findViewById(R.id.tv_part_name);
            holder.iv_isSelected = (ImageView) view.findViewById(R.id.iv_isSelected);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        CustomerSpinnerObject object = mDataList.get(i);
        holder.tv_part_name.setText(object.toString());
        if (object.isSelected()){
           holder.iv_isSelected.setVisibility(View.VISIBLE);
        }else{
            holder.iv_isSelected.setVisibility(View.INVISIBLE);
        }
        return view;
    }

    public static class ViewHolder{
        private TextView tv_part_name;
        private ImageView iv_isSelected;
    }
}
